<template>
  <div class="page">
    <div class="page-top">
      <!-- 面包屑 -->
      <Hreadcrumb :hreadcrumbAry="hreadcrumbAry" />
    </div>
    <div class="page-content">
      <a-form-model :model="form">
        <a-form-model-item prop="files">
          用友-京东编码关系对照表导入
          <a-upload
            :multiple="false"
            :customRequest="handleupload"
            :fileList="form.files"
            :remove="handleRemove"
          >
            <a-button>选择文件</a-button>
          </a-upload>
        </a-form-model-item>
        <a-form-model-item>
          <a-button type="primary" @click="uploadErpFile" :loading="loading"
            >提交</a-button
          >
        </a-form-model-item>
      </a-form-model>
      <a-form-model :model="formKD">
        <a-form-model-item prop="files">
          金蝶-京东编码关系对照表导入
          <a-upload
            :multiple="false"
            :customRequest="handleKDupload"
            :fileList="formKD.files"
            :remove="handleKDRemove"
          >
            <a-button>选择文件</a-button>
          </a-upload>
        </a-form-model-item>
        <a-form-model-item>
          <a-button type="primary" @click="uploadKDErpFile" :loading="KDloading"
            >提交</a-button
          >
        </a-form-model-item>
      </a-form-model>
      <a-form-model :model="formGY">
        <a-form-model-item prop="files">
          金蝶-管易编码关系对照表导入
          <a-upload
            :multiple="false"
            :customRequest="handleGYupload"
            :fileList="formGY.files"
            :remove="handleGYRemove"
          >
            <a-button>选择文件</a-button>
          </a-upload>
        </a-form-model-item>
        <a-form-model-item>
          <a-button type="primary" @click="uploadGYErpFile" :loading="GYloading"
            >提交</a-button
          >
        </a-form-model-item>
      </a-form-model>
      <a-form-model :model="formSCS">
        <a-form-model-item prop="files">
          管易-飞迩编码关系对照表导入
          <a-upload
            :multiple="false"
            :customRequest="handleSCSupload"
            :fileList="formSCS.files"
            :remove="handleSCSRemove"
          >
            <a-button>选择文件</a-button>
          </a-upload>
        </a-form-model-item>
        <a-form-model-item>
          <a-button type="primary" @click="uploadSCSErpFile" :loading="SCSloading"
            >提交</a-button
          >
        </a-form-model-item>
      </a-form-model>
      <a-form-model :model="formSF">
        <a-form-model-item prop="files">
          金蝶-盛丰编码关系对照表导入
          <a-upload
            :multiple="false"
            :customRequest="handleSFupload"
            :fileList="formSF.files"
            :remove="handleSFRemove"
          >
            <a-button>选择文件</a-button>
          </a-upload>
        </a-form-model-item>
        <a-form-model-item>
          <a-button type="primary" @click="uploadSFErpFile" :loading="SFloading"
            >提交</a-button
          >
        </a-form-model-item>
      </a-form-model>
      <a-form-model :model="formWDT">
        <a-form-model-item prop="files">
          金蝶-旺店通编码关系对照表导入
          <a-upload
            :multiple="false"
            :customRequest="handleWDTupload"
            :fileList="formWDT.files"
            :remove="handleWDTRemove"
          >
            <a-button>选择文件</a-button>
          </a-upload>
        </a-form-model-item>
        <a-form-model-item>
          <a-button type="primary" @click="uploadWDTErpFile" :loading="WDTloading"
            >提交</a-button
          >
        </a-form-model-item>
      </a-form-model>
    </div>
  </div>
</template>
<script>
import Hreadcrumb from "@/components/Hreadcrumb";
import { uploadErpFile,uploadKDErpFile,uploadGYErpFile,uploadSCSErpFile,uploadSFErpFile,uploadWDTErpFile } from "@/request/api";
export default {
  data() {
    return {
      loading: false,
      KDloading:false,
      GYloading:false,
      SCSloading:false,
      SFloading:false,
      WDTloading:false,
      FormData: null,
      KDFormData:null,
      SFFormData:null,
      WDTFormData:null,
      GYFormData:null,
      SCSFormData:null,
      hreadcrumbAry: [
        { name: "首页", path: "/", query: {} },
        { name: "erp管理", path: "/erp", query: {} },
      ],
      form: {
        files: [],
      },
      formKD: {
        files: [],
      },
      formGY: {
        files: [],
      },
      formSCS: {
        files: [],
      },
      formSF: {
        files: [],
      },
      formWDT: {
        files: [],
      },
    };
  },
  components: {
    Hreadcrumb,
  },
  methods: {
    handleupload(info) {
      console.log(info);
      this.form.files.push(info.file);
    },
    handleKDupload(info) {
      console.log(info);
      this.formKD.files.push(info.file);
    },
    handleGYupload(info) {
      console.log(info);
      this.formKD.files.push(info.file);
    },
    handleSCSupload(info) {
      console.log(info);
      this.formSCS.files.push(info.file);
    },
    handleSFupload(info) {
      console.log(info);
      this.formSF.files.push(info.file);
    },
    handleWDTupload(info) {
      console.log(info);
      this.formWDT.files.push(info.file);
    },
    handleRemove(file) {
      console.log(file);
      console.log(this.form.files);
      const index = this.form.files.indexOf(file);
      const newFileList = this.form.files.slice();
      newFileList.splice(index, 1);
      this.form.files = newFileList;
    },
    handleKDRemove(file) {
      const index = this.formKD.files.indexOf(file);
      const newFileList = this.formKD.files.slice();
      newFileList.splice(index, 1);
      this.formKD.files = newFileList;
    },
    handleGYRemove(file) {
      const index = this.formGY.files.indexOf(file);
      const newFileList = this.formGY.files.slice();
      newFileList.splice(index, 1);
      this.formGY.files = newFileList;
    },
    handleSCSRemove(file) {
      const index = this.formSCS.files.indexOf(file);
      const newFileList = this.formSCS.files.slice();
      newFileList.splice(index, 1);
      this.formSCS.files = newFileList;
    },
    handleSFRemove(file) {
      const index = this.formSF.files.indexOf(file);
      const newFileList = this.formSF.files.slice();
      newFileList.splice(index, 1);
      this.formSF.files = newFileList;
    },
    handleWDTRemove(file) {
      const index = this.formWDT.files.indexOf(file);
      const newFileList = this.formWDT.files.slice();
      newFileList.splice(index, 1);
      this.formWDT.files = newFileList;
    },
    onSubmit() {
      // this.uploadErpFile();
    },
    async uploadErpFile() {
      this.loading = true;
      this.FormData = new FormData();
      this.form.files.forEach((item) => {
        console.log(item);
        this.FormData.append("file", item);
      });
      console.log(this.FormData.has("file"));
      if (this.FormData.has("file")) {
        let { data } = await uploadErpFile(this.FormData);
        console.log(data);
        if (data.success) {
          this.loading = false;
          this.$message.success(data.content);
        } else {
          this.loading = false;
          this.$message.error(data.content);
        }
      } else {
        this.$message.warn("请选择文件");
        this.loading = false;
      }
    },
    async uploadKDErpFile() {
      this.KDloading = true;
      this.KDFormData = new FormData();
      this.formKD.files.forEach((item) => {
        console.log(item);
        this.KDFormData.append("file", item);
      });
      if (this.KDFormData.has("file")) {
        let { data } = await uploadKDErpFile(this.KDFormData);
        console.log(data);
        if (data.success) {
          this.KDloading = false;
          this.$message.success(data.content);
        } else {
          this.KDloading = false;
          this.$message.error(data.content);
        }
      } else {
        this.$message.warn("请选择文件");
        this.KDloading = false;
      }
    },
    async uploadSFErpFile() {
      this.KDloading = true;
      this.KDFormData = new FormData();
      this.formKD.files.forEach((item) => {
        console.log(item);
        this.KDFormData.append("file", item);
      });
      if (this.KDFormData.has("file")) {
        let { data } = await uploadSFErpFile(this.KDFormData);
        console.log(data);
        if (data.success) {
          this.KDloading = false;
          this.$message.success(data.content);
        } else {
          this.KDloading = false;
          this.$message.error(data.content);
        }
      } else {
        this.$message.warn("请选择文件");
        this.KDloading = false;
      }
    },
    async uploadWDTErpFile() {
      this.KDloading = true;
      this.KDFormData = new FormData();
      this.formKD.files.forEach((item) => {
        console.log(item);
        this.KDFormData.append("file", item);
      });
      if (this.KDFormData.has("file")) {
        let { data } = await uploadWDTErpFile(this.KDFormData);
        console.log(data);
        if (data.success) {
          this.KDloading = false;
          this.$message.success(data.content);
        } else {
          this.KDloading = false;
          this.$message.error(data.content);
        }
      } else {
        this.$message.warn("请选择文件");
        this.KDloading = false;
      }
    },
    async uploadGYErpFile() {
      this.GYloading = true;
      this.GYFormData = new FormData();
      this.formGY.files.forEach((item) => {
        console.log(item);
        this.GYFormData.append("file", item);
      });
      if (this.GYFormData.has("file")) {
        let { data } = await uploadGYErpFile(this.GYFormData);
        console.log(data);
        if (data.success) {
          this.GYloading = false;
          this.$message.success(data.content);
        } else {
          this.GYloading = false;
          this.$message.error(data.content);
        }
      } else {
        this.$message.warn("请选择文件");
        this.GYloading = false;
      }
    },
    async uploadSCSErpFile() {
      this.SCSloading = true;
      this.SCSFormData = new FormData();
      this.formSCS.files.forEach((item) => {
        console.log(item);
        this.SCSFormData.append("file", item);
      });
      if (this.SCSFormData.has("file")) {
        let { data } = await uploadSCSErpFile(this.SCSFormData);
        console.log(data);
        if (data.success) {
          this.SCSloading = false;
          this.$message.success(data.content);
        } else {
          this.SCSloading = false;
          this.$message.error(data.content);
        }
      } else {
        this.$message.warn("请选择文件");
        this.SCSloading = false;
      }
    },
  },
};
</script>
<style>
.page-content {
  background-color: #fff;
  padding: 25px;
}
</style>